package domain.components;

import java.awt.Color;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.appearances.Circle;

import domain.worm.StateFalling;

public class Bullet extends WormsComponent {

	private double speed= 0;
	private double maxSpeed= 0.5;
	private boolean flagFall;
	private double aceleracion =2;

	public Bullet(int aDiameter, int aHeight, double x, double y) {
		super(aDiameter, aHeight, x, y);
		this.setAppearance(new Circle(Color.green, aDiameter));
	}
	
	public Bullet(int aDiameter, int aHeight, double x, double y, double speed) {
		this(aDiameter, aHeight, x, y);
		this.speed = speed;
	}

	@Override
	public boolean isSolid() {
		return false;
	}
	

	@Override
	protected void onCollisionWithSolid(WormsComponent gc) {
	}

	@Override
	protected void defineCollide(WormsComponent gc) {
		gc.collideWithProyectile(this);
	}

	/*
	 * No anda 
	 * falta terminar fue copy paste
	 * */
	
	protected void effectiveUpdate(DeltaState deltaState) {
		double vix = Math.cos(45);
		double viy = Math.sin(45);
		
		if((this.speed < this.maxSpeed ) & !flagFall){
				this.speed = this.speed + this.aceleracion  * deltaState.getDelta();
				if (!this.collide(this.getX()+vix, this.getY() -(this.speed*viy))){
					this.updateCoords(vix, -(this.speed*viy));
				}
				
		}
		else{
			this.flagFall = true;
			this.speed = this.speed + (-this.aceleracion) * deltaState.getDelta();
			// this.updateCoords(vix, -(this.speed*viy));}
			if (!this.collide(this.getX()+vix, this.getY() -(this.speed*viy))){
				this.updateCoords(vix, -(this.speed*viy));
			}
			
		}

	}

	@Override
	public boolean collideWithRect(WormsComponent rect) {
		return this.rectCircleCollide(this, rect);
	}

	@Override
	public boolean collideWithCircle(WormsComponent circle) {
		return this.circleCircleCollide(circle);
	}

	@Override
	public boolean collisionNature(WormsComponent target) {
		return target.collideWithCircle(this);
	}

}
